import requests

from APIs.baseAPI import BaseAPI
from APIs.loginAPI import LoginAPI
from common.config import ip


class LogAPI(BaseAPI):
    def wenShan(self):
        # 文件上传-新增/修改日志接口
        filew = r'D:\RCe\Rce\RCeJieKouzdh\datas\1.jpg'
        zengdata = {'type': 'img'}
        zengfile = {'file': ('1.jpg',
                             open(filew, 'rb'),
                             'image/jpeg')}
        z = requests.post(f'{ip}/file/upload',
                          data=zengdata,
                          files=zengfile,
                          headers=self.header)
        print(z.json())
        return z.json()

    def addlog(self,myjson1):
        # 新增日志
        # zengjson = {
        #     "categoryId": "1",
        #     "content": "cccccc",
        #     "tomorrow": "aaaaaa",
        #     "question": "bbbbbbb",
        #     "batchId": "721dcd430a96db886ae30343b789e26d",
        #     "sendUserIds": "",
        #     "sendDeptIds": "",
        #     "customerIds": "",
        #     "contactsIds": "",
        #     "businessIds": "",
        #     "contractIds": ""
        # }
        zengjson =myjson1
        xz = requests.post(f'{ip}/OaLog/addOrUpdate', json=zengjson, headers=self.header)
        print(xz.json())
        return xz.json()

    def xiulog(self,myjson2):
        # 修改日志
        # xiujson = {
        #     "logId": 2,
        #     "categoryId": "1",
        #     "content": "今天的修改",
        #     "tomorrow": "修改修改",
        #     "question": "嗷嗷嗷啊吖",
        #     "batchId": "721dcd430a96db886ae30343b789e26d",
        #     "sendUserIds": "",
        #     "sendDeptIds": "",
        #     "customerIds": "",
        #     "contactsIds": "",
        #     "businessIds": "",
        #     "contractIds": ""
        # }
        xiujson=myjson2
        xiu = requests.post(f'{ip}/OaLog/addOrUpdate', json=xiujson, headers=self.header)
        print(xiu.json())
        return xiu.json()

    def chalog(self,myjson3):
        # 获取日志列表
        # huojson = {
        #     "page": 1,
        #     "limit": 50
        # }
        huojson=myjson3
        huo = requests.post(f'{ip}/OaLog/queryList', json=huojson, headers=self.header)
        # rlist = huo.json()['data']['list'][0]['logId']
        print(huo.json())
        return huo.json()

    def chamylog(self):
        # 获取日志列表
        myhuojson = {
            "page": 1,
            "limit": 5,
            "by":1
        }
        myhuo = requests.post(f'{ip}/OaLog/queryList', json=myhuojson, headers=self.header)
        mrlist = myhuo.json()['data']['list']
        print(mrlist)
        return mrlist

    def dellog(self):
        delist=self.chalog({"page": 1,"limit": 50})['data']['list'][0]['logId']
        # 获取全部logid
        # ls=[]
        # for i in delist:
        #     ls.append(i['logId'])
        #     print(ls)
        #     # 删除日志--删除多个
        # sdata={'logId':ls}
        sdata = {'logId': delist}
        s=requests.post(f'{ip}/OaLog/deleteById',data=sdata,headers=self.header)
        print(s.json())
        return s.json()
    #删除全部
    def delqlog(self):
        delist2=self.chamylog()
        # 获取全部logid
        ls=[]
        for i in delist2:
            ls.append(i['logId'])
            print(ls)
            # 删除日志--删除多个
        sdata1={'logId':ls}
        # sdata = {'logId': delist}
        s1=requests.post(f'{ip}/OaLog/deleteById',data=sdata1,headers=self.header)
        print(s1.json())
        return s1.json()
if __name__ == '__main__':
    l=LoginAPI()
    r=l.gettoken()
    print(r)
    log=LogAPI(r)
    # log.addlog()
    # log.dellog()
    # rr=log.chalog({"page": 1,"limit": 5})['code']
    # print(rr)
    # log.chamylog()
    log.dellog()
    # log.wenShan()
    # log.delqlog()







